package com.qifan.alb2b.action.front;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qifan.alb2b.action.back.param.RouteQueryParam;
import com.qifan.alb2b.domain.NewsInfoDomain;
import com.qifan.alb2b.domain.PictureInfoDomain;
import com.qifan.alb2b.service.NewsInfoService;
import com.qifan.alb2b.service.PictureInfoService;
import com.qifan.alb2b.service.RouteInfoService;
import com.qifan.alb2b.util.Constants;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.Page;

/**
 * 显示首页相关的信息
 * @author hc24
 *
 */
@Controller
@RequestMapping("/index")
public class IndexController {
	private RouteInfoService routeInfoService;
	private NewsInfoService newsInfoService;
	private PictureInfoService pictureInfoService;
	
	public void setRouteInfoService(RouteInfoService routeInfoService) {
		this.routeInfoService = routeInfoService;
	}

	public void setNewsInfoService(NewsInfoService newsInfoService) {
		this.newsInfoService = newsInfoService;
	}

	public void setPictureInfoService(PictureInfoService pictureInfoService) {
		this.pictureInfoService = pictureInfoService;
	}

	@RequestMapping("getHoteRoute.usr")
	@ResponseBody
	public Map<String, Object> getHotRoute(){
		RouteQueryParam rqp=new RouteQueryParam();
		rqp.setStatus(Constants.ROUTE_STATUS_OPEN);//只返回开通的线路
		rqp.setHot(Constants.INS_YES);
		DataGridModel dgm=new DataGridModel();
		dgm.setPage(1);
		dgm.setRows(10);
		dgm.setSort("createDate");
		dgm.setOrder("desc");
		Page page= routeInfoService.query(dgm, rqp);
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("success", true);
		map.put("routes", page.getRows());
		return map;
	}
	
	@RequestMapping("getNews.usr")
	@ResponseBody
	public Map<String, Object> getNews(){
		DataGridModel dgm=new DataGridModel();
		dgm.setPage(1);
		dgm.setRows(12);
		dgm.setSort("publicTime");
		dgm.setOrder("desc");
		NewsInfoDomain nid=new NewsInfoDomain();
		nid.setStatus(1);
		Page page= newsInfoService.query(dgm, nid);
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("news", page.getRows());
		map.put("success", true);
		return map;
	}
	
	@RequestMapping("getComp.usr")
	@ResponseBody
	public Map<String, Object> getComp(){
		List<NewsInfoDomain> list= newsInfoService.getCompNews("1");
		String comp="";
		if(list.size()>0)
			comp=list.get(0).getNewsContent();
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("comp", comp);
		map.put("success", true);
		return map;
	}
	
	@RequestMapping("getContact.usr")
	@ResponseBody
	public Map<String, Object> getContact(){
		List<NewsInfoDomain> list= newsInfoService.getCompNews("2");
		String contact="";
		if(list.size()>0)
			contact=list.get(0).getNewsContent();
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("contact", contact);
		map.put("success", true);
		return map;
	}
	
	@RequestMapping("getPics.usr")
	@ResponseBody
	public Map<String, Object> getPics(){
		DataGridModel dgm=new DataGridModel();
		dgm.setPage(1);
		dgm.setRows(6);
		dgm.setSort("sortNo");
		dgm.setOrder("asc");
		PictureInfoDomain pid=new PictureInfoDomain();
		Page page= pictureInfoService.query(dgm, pid);
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("pics", page.getRows());
		map.put("success", true);
		return map;
	}
}
